package ordering.stat;



import general.constraints.Constraints;

public class OpConflictOrdering extends StaticOrdering{
	public OpConflictOrdering(int n, Constraints constraints) {
		int[] numConflicts = new int[n];
		byte[] ordering = new byte[n];
		//i was lazy to implement a sorting algorithm so i just used the simplest one
		for (byte i=0; i<n; i++){
			numConflicts[i] = constraints.getNumConflicts(i);
			ordering[i] = i;
		}
		for (byte i=0; i<n; i++){
			for (byte j=(byte)(i+1); j<n; j++){
				if (numConflicts[i]>numConflicts[j]){
					byte tmp1 = ordering[i];
					int tmp2 = numConflicts[i];
					ordering[i] = ordering[j];
					numConflicts[i] = numConflicts[j];
					ordering[j] = tmp1;
					numConflicts[j] = tmp2; 
				}
			}
		}
//		System.out.println(Arrays.toString(ordering));
//		System.out.println(Arrays.toString(numConflicts));
		setArray(ordering);
	}
}
